/* EBL marker routines.
 *
 * Copyright (c) 2006 Els Kok
 *
 * This file is part of libMask.
 *
 * libMask is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * libMask is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with libMask.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "mask.h"

/****************************************************************/
/* Global marker for e-beam alignment                           */
/* cp is in the center of the mark                              */
/* DON'T FORGET TO ADD LOCAL MARKS!!                            */
/****************************************************************/
void EBL_global_mark(){
  
  double GlobalArmWidth = 5.0e-6;
  double GlobalArmLength = 49.0e-6;
    
  rect(GlobalArmLength, GlobalArmWidth, 5, 5);
  rect(GlobalArmWidth, GlobalArmLength, 5, 5);
 
}


/****************************************************************/
/* Local marker for e-beam alignment                            */
/* cp should be in the center of the manual scan field          */
/* it's left in the center as well                              */
/****************************************************************/
void EBL_local_mark(double ScanFieldSize, double ArmLength, int Inverse){
  
  double ArmWidth = 1.0e-6;
  double AutoScanLength = 6.0e-6;
  double AutoScanWidth = 0.5e-6;
  
  int savelayer = clayer; /* remember the current layer */

  ScanFieldSize = ScanFieldSize - 0.2e-6; /* to make sure that the scan
					     field is completely inside the
					     write field */
  if (Inverse == 0){
    rect(ArmLength, ArmWidth, 5, 5);
    rect(ArmWidth, ArmLength, 5, 5);
  } 
  else {  /* inverse mark */
    push_cp();
    move(-0.5 * ArmWidth, 0.5 * ArmWidth, 0, 0);
    rect( (0.5 * (ArmLength - ArmWidth)), (0.5 * (ArmLength - ArmWidth)), 3, 3);
    offset(ArmWidth);
    rect( (0.5 * (ArmLength - ArmWidth)), (0.5 * (ArmLength - ArmWidth)), 9, 9);
    skip(ArmWidth);
    rect( (0.5 * (ArmLength - ArmWidth)), (0.5 * (ArmLength - ArmWidth)), 7, 7);
    offset(-ArmWidth);
    rect( (0.5 * (ArmLength - ArmWidth)), (0.5 * (ArmLength - ArmWidth)), 1, 1);
    pop_cp();
    
    push_cp();
    skip(-0.5 * ArmLength);
    rect((0.5 * (ScanFieldSize - ArmLength)), ScanFieldSize, 6, 6);
    move(0.5 * ArmLength, 0.5 * ArmLength, 0, 0);
    rect(ScanFieldSize, (0.5 * (ScanFieldSize - ArmLength)), 2, 2);
    move(0, -ArmLength, 0, 0);
    rect(ScanFieldSize, (0.5 * (ScanFieldSize - ArmLength)), 8, 8);
    move(0.5 * ArmLength, 0.5 * ArmLength, 0, 0);
    rect((0.5 * (ScanFieldSize - ArmLength)), ScanFieldSize, 4, 4);
    pop_cp();
  }
  
  /* Scan fields for automatic alignment */
  layer(L_scanAutoEBL);
  push_cp();
  move(0.25 * ArmLength, 0.5 * AutoScanLength, -RAD(90), NOFLIP);
  if (mode & POLYGON) {
    mode &= ~POLYGON;
    sw(AutoScanLength, AutoScanWidth);
    mode |= POLYGON;
  } else {
    sw(AutoScanLength, AutoScanWidth);   }
  pop_cp();
  
  push_cp();
  move(-0.5 * AutoScanLength, 0.25 * ArmLength, 0, NOFLIP);
  if (mode & POLYGON) {
    mode &= ~POLYGON;
    sw(AutoScanLength, AutoScanWidth);
    mode |= POLYGON;
  } else {
    sw(AutoScanLength, AutoScanWidth);
  }
  pop_cp();

  /* Scan fields for manual alignment */
  layer(L_scanManualEBL);
  push_cp();
  skip(-0.5 * ScanFieldSize);
  sw(ScanFieldSize, ScanFieldSize);
  pop_cp();
  
  layer(savelayer); /* return to the present layer */
 
}
